import Vue from "vue";
// import * as Models from "@/api/shops";
const pages = {
  created() {


  },

  methods: {
    tableRowClassName({row, rowIndex}) {
      if (row.id == this.$route.params.current) {
        return 'success-row';
      }
      return '';
    },
    init() {
      this.vm.query = {};
      this.vm.models = [];
      this.vm.isNull = false;
      this.vm.isLoading = false;
      this.vm.isError = false;
      this.vm.meta = {};
      this.vm.query.keyword = ''
    },
    reset() {

      this.vm.query.page = 1;
      this.vm.query.size = 10;

    },

    queryTag(keyword) {
      this.vm.query.keyword = keyword;
      this.query({relod: true})
    },
    query(config) {

      if (config && config.reload) {
        this.reset();
      }
      this.queryConfig = this.queryConfig ? this.queryConfig : '';
      this.vm.models = [];
      this.vm.isLoading = true;

      this.Models.query(this.vm.query, this.queryConfig)
        .then((data) => {
          this.vm.isLoading = false;
          this.vm.models = data.models;
          if (data.meta) {
            this.vm.meta = {
              size: data.meta.size * 1,
              page: data.meta.page * 1,
              total: data.meta.total * 1
            };
          }
        })
        .catch((err) => {
          console.warn(err);
          this.vm.isLoading = false;
          this.vm.isError = true;
        });
    },
    pageChange(e) {
      Vue.set(this.vm.query, "page", e);
      this.query();
    },
    sizeChange(e) {
      Vue.set(this.vm.query, "page", 1);

      Vue.set(this.vm.query, "size", e);
      this.query();
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    getIds(list) {
      let ids = [];
      if (list.length) {
        for (let i = 0; i < list.length; i++) {
          ids.push(list[i].id)
        }
      }
      return ids;
    },
    del(id) {

      this.$confirm("删除将无法恢复, 是否确定", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.Models.del(id).then(function (res) {
            if (res.result == "ok") {
              this.query({reload: true});
              this.$message({
                type: "success",
                message: "删除成功!"
              });
            } else {
              this.$message({
                type: "warning",
                message: "删除失败!"
              });
            }
          });
        });
    }
  }
};
export default pages
